package cn.cdeden.knowledge.dubbo;

import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.knowledge.api.domain.RemoteQaFilesTreeService;
import cn.cdeden.knowledge.api.domain.vo.RemoteQaFilesTreeVo;
import cn.cdeden.knowledge.domain.QaFilesTree;
import cn.cdeden.knowledge.service.QaFilesTreeService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
@RequiredArgsConstructor
public class RemoteQaFilesTreeServiceImpl implements RemoteQaFilesTreeService {

    private final QaFilesTreeService qaFilesTreeService;

    @Override
    public List<RemoteQaFilesTreeVo> getAllQaFiles() {
        List<QaFilesTree> qaFilesTreeList = qaFilesTreeService.list();
        return MapstructUtils.convert(qaFilesTreeList, RemoteQaFilesTreeVo.class);
    }

    @Override
    public Boolean deleteAllQaFiles() {
        return qaFilesTreeService.remove(null);
    }

    @Override
    public RemoteQaFilesTreeVo getStorageId(String fileName, String userId) {
        QaFilesTree storageId = qaFilesTreeService.getStorageId(fileName, userId);
        return MapstructUtils.convert(storageId, RemoteQaFilesTreeVo.class);
    }
}
